<?php

class M_auth Extends MY_Model
{
	public function __construct()
	{
		parent::__construct();
		$this->load->library('hash');
	
	}
	
	
	public function _create_password($string = '')
	{
		return Hash::make($string);
	}
	
	private function _verify_password($password  = '',$password_from_db = '')
	{
		return Hash::check($password,$password_from_db);
	}
	
	public function validate_login($username_u384 = FALSE,$password_p384 = FALSE,$usertype_t384 = FALSE)
	{
		if($username_u384 AND $password_p384 AND $usertype_t384)
		{
			$username = trim(htmlspecialchars($username_u384));
			$password = trim(htmlspecialchars($password_p384));
			$table = parent::$usr_table;
			
			$sql = "SELECT employee_password from {$table}
					WHERE employee_username	= ? 
					AND login_role = ?
					AND login_status = 1";
			$qry = $this->db->query($sql,array($username,$usertype_t384));
		
			if($qry->num_rows() >= 1)
			{
				$password_from_db = $qry->row()->employee_password;
				if($this->_verify_password($password,$password_from_db))
				{
					$ci =& get_instance();
					$ci->session->set_userdata('isloggedtrue',TRUE);
					$ci->session->set_userdata('loginuser',$usertype_t384);
					return TRUE;
				}else{
					return FALSE;
				}
			}else{
				return FALSE;
			}
		}else{
			return FALSE;
		}
	}
}